<template>
  <div>
    <div class="ser_div">
      <el-row>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.order_number" type="number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 流水号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.serial_number"></el-input>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 经销商 </el-col>
            <el-col :span="16">
              <el-select
                v-model="ser.customer_id"
                filterable
                placeholder="请选择经销商"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in CustomerList"
                  :key="index"
                  :label="item.customer_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 产品 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.product_id" filterable @change="product_id_change" placeholder="请选择产品"
                style="width: 100%">
                <el-option v-for="(item, index) in productList" :key="index" :label="item.product_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>-->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 发货司机 </el-col>
            <el-col :span="16">
              
              <el-select v-model="ser.driver_id" placeholder="请选择司机">
              <el-option
                v-for="item in driverList"
                :key="item.id"
                :label="item.company_name"
                :value="item.id"
              >
              </el-option>
            </el-select>
            </el-col>
          </el-row>
        </el-col> 
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 状态 </el-col>
            <el-col :span="16">
              <el-select
                v-model="ser.logistics_status"
                placeholder="请选择物流状态"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in logistics_statuslist"
                  :key="index"
                  :label="item.lable"
                  :value="item.status"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 分厂 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                clearable
                allow-create
                v-model="ser.branch_factory_id"
                placeholder="请选择生产厂家"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in FactoryList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
               <el-input
                v-model="ser.branch_factory_id"
                placeholder="请输入内容"
                style="width: 100%"
                clearable
              />
            </el-col>
          </el-row>
        </el-col> -->
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 司机 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.driver_id" placeholder="请选择">
                <el-option v-for="item in YuanGongList" :key="item.id" :label="item.username" :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>  -->

        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 发货日期 </el-col>
            <el-col :span="16">
              <el-date-picker
                v-model="order_datas"
                @change="order_data_changes"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-button @click="search(0)" class="add_btn" icon="el-icon-search"
            >查询</el-button
          >
          <el-button @click="searchreset" icon="el-icon-refresh" class="add_btn"
            >重置</el-button
          >
          <el-button @click="search(2)" icon="el-icon-plus" class="add_btn"
            >导出</el-button
          >
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="dataList"
      v-horizontal-scroll="'always'"
      stripe
      v-loading="loading"
      style="width: 100%"
      border
    >
      <!-- <el-table-column type="selection"> </el-table-column> -->
      <el-table-column prop="id" label="ID" width="60"> </el-table-column>

      <el-table-column label="经销商" width="80">
        <template slot-scope="scope">
          {{ scope.row.customer ? scope.row.customer.customer_name : "" }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="业主地址" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.customer_name }}
        </template>
      </el-table-column>
      <el-table-column label="业主电话" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.customer_phone }}
        </template>
      </el-table-column> -->
     
      
      <el-table-column label="订单号" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_number }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="流水号" width="70">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.serial_number }}
        </template>
      </el-table-column> -->

      <el-table-column prop="receivables" label="应收款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.receivables }}
        </template>
      </el-table-column>
      <el-table-column prop="received" label="已收款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.received }}
        </template>
      </el-table-column>
      <el-table-column label="尾款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.owe_price }}
        </template>
      </el-table-column>
      <el-table-column label="仓库" width="80">
        <template slot-scope="scope">
          {{ scope.row.warehouse ? scope.row.warehouse.warehouse_name : "" }}
        </template>
      </el-table-column>
      <el-table-column label="订单备注">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.remark }}
        </template>
      </el-table-column>
      <el-table-column label="发货司机" width="100">
        <template slot-scope="scope">
          {{ scope.row.user?scope.row.user.company_name:"" }}
        </template>
      </el-table-column>
      <el-table-column prop="logistics_status" label="发货状态" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.logistics_status == 1" style="color: #dd8211"
            >待发货</span
          >
          <span v-if="scope.row.logistics_status == 2" style="color: #f1420d"
            >未发货</span
          >
          <span v-if="scope.row.logistics_status == 3" style="color: #0ca163"
            >已发货</span
          >
          <span v-if="scope.row.logistics_status == 4" style="color: #c9be2f"
            >部分待发货</span
          >
          <span v-if="scope.row.logistics_status == 5" style="color: #c9be2f"
            >部分未发货</span
          >
          <span
            v-if="scope.row.logistics_status == 6"
            style="color: #4e4a4c; font-weight: bold"
            >已退货</span
          >
        </template>
      </el-table-column>

      <!-- <el-table-column label="已发件数" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.sent_num }}
        </template>
      </el-table-column>
      <el-table-column label="待发件数" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.to_be_sent_num }}
        </template>
      </el-table-column> -->
      
      <el-table-column
        prop="logistics_type"
        :formatter="formatterTime"
        label="发货类型"
        width="120"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.logistics_type==1">自提</span>
          <span v-if="scope.row.logistics_type==2">物流</span>
          <span v-if="scope.row.logistics_type==1">整车</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="delivery_time"
        :formatter="formatterTime"
        label="发货时间"
        width="120"
      >
        <template slot-scope="scope">
          {{ scope.row.delivery_time }}
        </template>
      </el-table-column>
      <el-table-column label="发货备注" width="120">
        <template slot-scope="scope">
          {{ scope.row.logistics_remark }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.logistics_status == 3"
            @click="fahuo_s(scope.row)"
            type="text"
            >发货</el-button
          >
          <!-- <el-button
            v-if="scope.row.logistics_status == 3"
            @click="huanhuo_add_show(scope.row)"
            type="text"
            >换货</el-button
          >
           <el-button
            type="text"
            @click="
              chengpin_shanchu(scope.row.id, scope.row.order.order_number)
            "
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        @prev-click="prev"
        @next-click="next"
        :current-page.sync="pagination.page"
        :page-size="pagination.per_page"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>

  
    <el-dialog
      title="发货信息"
      v-if="isjilu"
      :visible.sync="isjilu"
      width="70%"
      @close="close_dialog"
    >
      <el-table
        :data="dataList_product[0].order.order_second"
        v-horizontal-scroll="'always'"
        stripe
        style="width: 100%"
        ref="multipleTable"
        @selection-change="handleSelectionChange_product"
        border
      >
      
      <el-table-column type="selection"> </el-table-column>
      <el-table-column label="ID" :width="50">
          <template slot-scope="prop_s">
            <span>{{prop_s.row.id}}</span>
          </template>
        </el-table-column>  
        <el-table-column label="产品" >
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.product ? prop_s.row.product.product_name : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="型号">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.model_number
                ? prop_s.row.model_number.model_number
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="颜色">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.color ? prop_s.row.color.color : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="规格">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.specification
                ? prop_s.row.specification.specification
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="尺寸" :width="100">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.work_size }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数量" :width="60">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.num }}</span>
          </template>
        </el-table-column>
        <el-table-column label="待发数量" prop="nums" :width="200">
          <template slot-scope="prop_s">
            <el-input-number
              v-model="prop_s.row.nums"
              :min="1"
              :max="prop_s.row.num"
            />
          </template>
        </el-table-column>
      </el-table>

      <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 发货司机 </el-col>
        <el-col :span="21">
          <el-select v-model="fahuos.driver_id" placeholder="请选择司机">
              <el-option
                v-for="item in driverList"
                :key="item.id"
                :label="item.company_name"
                :value="item.id"
              >
              </el-option>
            </el-select>
        </el-col>
      </el-row>
      <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 发货类型 </el-col>
        <el-col :span="21">
          <el-select
            v-model="fahuos.logistics_type"
            placeholder="请选择发货类型"
          >
            <el-option
              v-for="item in wuliulist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 物流 </el-col>
        <el-col :span="21">
          <el-input type="text" v-model="fahuos.logistics_company"></el-input>
        </el-col>
      </el-row>
      <!-- <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 发货内容 </el-col>
        <el-col :span="21">
          <el-input type="text" v-model="fahuos.logistics_info"></el-input>
        </el-col>
      </el-row> -->
      <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 备注 </el-col>
        <el-col :span="21">
          <el-input type="text" v-model="fahuos.logistics_remark"></el-input>
        </el-col>
      </el-row>
      <!-- <el-row style="display: flex; align-items: center; margin-top: 15px">
        <el-col :span="3"> 短信提醒 </el-col>
        <el-col :span="21">
          <el-switch
            v-model="fahuos.duanxin"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-col>
      </el-row> -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="isjilu = false" type="primary" size="small"
          >取 消</el-button
        >
        <el-button @click="yes_fahuo" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="换货详情"
      :visible.sync="is_addreturn_list"
      width="60%"
      @close="tui_huan_change"
    >
      <el-table :data="semi_finish_product">
        <el-table-column label="产品类型" width="150">
          <template slot-scope="prop">
            <span>{{ prop.row.models ? prop.row.models.modelname : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品" width="150">
          <template slot-scope="prop">
            <span>{{
              prop.row.product ? prop.row.product.product_name : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="型号" width="150">
          <template slot-scope="prop">
            <span>{{
              prop.row.model_number ? prop.row.model_number.model_number : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="规格" width="150">
          <template slot-scope="prop">
            <span>{{
              prop.row.specification ? prop.row.specification.specification : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="颜色" width="150">
          <template slot-scope="prop">
            <span>{{ prop.row.color ? prop.row.color.color : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="90">
          <template slot-scope="scope">
            <el-button
              @click="
                huanhuo_add(
                  scope.row.id,
                  scope.row.product_id,
                  scope.row.model_number_id,
                  scope.row.color_id,
                  scope.row.specification_id
                )
              "
              type="text"
              >换货</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="数量" width="150">
          <template slot-scope="prop">
            <span>{{ prop.row.num ? prop.row.num : "" }}</span>
          </template>
        </el-table-column>
      </el-table>

      <el-button @click="is_addreturn_list = false">取 消</el-button>
    </el-dialog>

    <!-- huanhuo -->
    <el-dialog
      title="新增换货"
      :visible.sync="is_addreturn"
      width="30%"
      @close="tui_huan_change"
    >
      <el-form
        label-width="100px"
        ref="ruleForm"
        :model="add_return"
        :rules="rules"
      >
        <el-form-item label="换货时间" prop="exchange_time">
          <el-date-picker
            v-model="add_return.exchange_time"
            value-format="yyyy-MM-dd"
            align="right"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input-number v-model="add_return.num" :min="1"></el-input-number>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            style="width: 80%"
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="add_return.remark"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="is_addreturn = false">取 消</el-button>
        <el-button type="primary" @click="add_huanhuos('ruleForm')"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getFinishProductList,
  getStockAllocationList,
  stockAllocation,
  setDeliveryStatus,
  DeliverGoods,
  getCustomerList,
  getModelNumberList,
  getProductList,
  delFinishProduct,
  getFinishProductList_exports,
  getInventoryCount,
  exchangeGoods,
  logisticsCompany,
  getUserList,
  getBranchFactoryList,
  getFinishProductDetail,
  getDriverList
} from "@/api/product/index";
export default {
  data() {
    return {
      is_addreturn_list: false,
      is_addreturn: false,
      loading: true,
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      FactoryList: [],
      YuanGongList: [],
      logistics_statuslist: [
        {
          status: 1,
          lable: "待发货",
        },
        {
          status: 3,
          lable: "已发货",
        },
      ],
      dataList_fahuo: [],
      // 搜索
      ModelNumberLists: [],
      ModelNumberList: [],
      order_data: [],
      order_datas: [],
      semi_finish_product: [],
      ser: {
        branch_factory_id: "",
        serial_number: "",
        logistics_status: "",
        driver_id: "",
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
        delivery_time_s: "",
        delivery_time_e: "",
      },
      CustomerList: [],
      productList: [],
      wuliulist: [
        {
          label: "自提",
          value: 1,
        },
        {
          label: "物流",
          value: 2,
        },
        {
          label: "整车",
          value: 3,
        },
      ],
      isdayin: false,
      isjilu: false,
      ishuojia: false,
      dataList: [],
      pagination: {
        per_page: 10,
        page: 1,
      },
      total: 0,
      dayinlist: [],
      diaoList: [],
      finish_product_id: "",
      diaohuojilulist: [],
      datalists: [],
      selectedRows:[],
      fahuos: {
        order_seconds: [],
        driver_id:"",
        finish_product_id: "",
        logistics_status:"",
        logistics_company: "",
        logistics_type: 2,        
        logistics_remark: "",
        duanxin: false,
      },
      add_return: {
        remark: "",
        semi_id: "",
        num: "",
        exchange_time: "",
      },
      rules: {
        exchange_time: [
          { required: true, message: "请选择活时间", trigger: "blur" },
        ],
      },
      logisticsCompanyList: [],
      dataList_product: [],
      driverList:[]
    };
  },
  mounted() {
    this.getlist();
    this.getproduct();
    this.getModel();
    this.getCustomer();
    this.get_YuanGongList();
    this.get_BranchFactoryList_s();
    this.get_driverList()
  },
  methods: {
    get_driverList(){
      getDriverList().then(res=>{
        if(res.code==200){
          this.driverList = res.data
        }
      })
    },
    get_BranchFactoryList_s() {
      getBranchFactoryList({ is_simple: 1 }).then((res) => {
        if (res.code == 200) {
          this.FactoryList = res.data;
        }
      });
    },
    get_YuanGongList() {
      getUserList().then((res) => {
        if (res.code == 200) {
          this.YuanGongList = [];
          res.data.data.forEach((item) => {
            if (item.role[0].name == "送货司机") {
              this.YuanGongList.push(item);
            }
          });
          console.log(this.YuanGongList);
        }
      });
    },
    log_isticsCompany() {
      logisticsCompany().then((res) => {
        if (res.code == 200) {
          this.logisticsCompanyList = res.data;
        }
      });
    },
    huanhuo_add_show(row) {
      this.is_addreturn_list = true;

      this.semi_finish_product = row.semi_finish_product;
    },
    tui_huan_change() {
      this.add_return = {
        remark: "",
        semi_id: "",
        exchange_time: "",
      };
    },
    add_huanhuos(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          exchangeGoods(this.add_return).then((res) => {
            if (res.code == 200) {
              this.add_return = {
                remark: "",
                semi_id: "",
                exchange_time: "",
              };
              this.is_addreturn = false;
              this.is_addreturn_list = false;
              this.getlist();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    huanhuo_add(id, id_1, id_2, id_3, id_4) {
      let obj = {
        product_id: id_1 ? id_1 : "",
        model_number_id: id_2 ? id_2 : "",
        color_id: id_3 ? id_3 : "",
        specification_id: id_4 ? id_4 : "",
      };
      getInventoryCount(obj).then((res) => {
        if (res.code == 200) {
          if (res.data == 0) {
            this.$message.error("暂无可换货产品");
          } else {
            this.is_addreturn = true;
            this.title = "新增换货";
            this.add_return.semi_id = id;
          }
        }
      });
    },
    del_FinishProduct(id) {
      delFinishProduct({ finish_product_id: id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      });
    },
    chengpin_shanchu(id, num) {
      this.$confirm("您确定删除订单号为：" + num + "的订单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.del_FinishProduct(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 指定查询
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      getFinishProductList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      getFinishProductList_exports(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "物流列表";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    searchreset() {
      this.ser = {
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
        branch_factory_id: "",
      };
      this.getlist();
    },
    //客户列表
    getCustomer() {
      getCustomerList({ per_page: 99999 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    // 型号列表
    getModel() {
      getModelNumberList().then((res) => {
        if (res.code == 200) {
          this.ModelNumberLists = res.data.data;
        }
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
    order_data_changes(val) {
      this.ser.delivery_time_s = val[0];
      this.ser.delivery_time_e = val[1];
    },
    product_id_change(val) {
      console.log(val);
      this.ser.model_number_id = "";
      this.get_producModel(val);
    },
    get_producModel(id) {
      getModelNumberList({
        product_id: id,
        field_list: "id,model_number",
        is_dropdown: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data.data;
        }
      });
    },
    push_daifahuo() {
      let ids = [];
      this.dayinlist.forEach((item) => {
        ids.push(item.id);
      });
      setDeliveryStatus({ ids }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
        }
      });
    },
    fahuo_s(row) {
      this.dataList_product=[];
      this.fahuos.finish_product_id = row.id;
      this.fahuos.driver_id=row.user?row.user.id:''
      this.fahuos.logistics_company = "";
      // console.log(this.dataList_fahuo);
      getFinishProductDetail({ finish_product_id: row.id }).then((res) => {
        if (res.code == 200) {
          this.isjilu = true;
          this.get_driverList()
          res.data.forEach((item) => {
            let obj = {
              ...item
            };
            obj.order.order_second.forEach((secend)=>{
              secend.nums = secend.num
            });
            console.log('obj',obj)
            this.dataList_product.push(obj);
          });
          if (this.dataList_product.length === res.data.length) {
            this.$nextTick(() => {
              this.$refs.multipleTable.toggleAllSelection();
              // this.$refs.multipleTable.toggleRowSelection();
            });
          }
          // this.$refs.multipleTable.toggleAllSelection();
        }
      });
    },
    fahuo(row) {
      this.isjilu = true;
      console.log('row111',row);
      // this.log_isticsCompany()
    },
    yes_fahuo() {
      this.fahuos.order_seconds = [];      
      this.dataList_product[0].order.order_second.forEach((item) => {
        let selected = this.isRowSelected(item);
        let obj = {
          id: item.id,
          num: item.nums,
          checked: selected
        };
        this.fahuos.order_seconds.push(obj);
      });
      console.log(this.fahuos);

      DeliverGoods(this.fahuos).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.isjilu = false;
          this.getlist();
        }
      });
    },
    diaohuojilu(row) {
      this.isjilu = true;
      this.diaohuojilulist = row.stock_allocation_log;
    },
    close_dialog() {
      this.finish_product_id = "";
      this.diaohuojilulist = [];
    },
    //调货确认
    add_product(row) {
      stockAllocation({
        order_id: row.id,
        finish_product_id: this.finish_product_id,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
          this.fahuos = {
            finish_product_id: "",
            logistics_status: "",
            logistics_id: "",
            remark: "",
            logistics_info: "",
            duanxin: false,
          };
          this.ishuojia = false;
        }
      });
    },
    diaohuo(row) {
      this.finish_product_id = row.id;
      getStockAllocationList({ id: row.id }).then((res) => {
        if (res.code == 200) {
          this.diaoList = res.data.data;
          this.ishuojia = true;
        }
      });
    },
    // 获取成品库列表
    getlist() {
      getFinishProductList({
        ...this.pagination,
        ...this.ser,
        order_type: "logistics",
      }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },
    isRowSelected(row) {
      return this.selectedrows.includes(row);
    },
    handleSelectionChange(val) {
      console.log(val);
      // this.dayinlist = val;
      this.datalists = val;
    },
    handleSelectionChange_product(val) {
      console.log('val',val);
      this.selectedrows = val;            
      console.log('selectedrows',this.selectedrows);
      /*
      this.fahuos.order_seconds = [];
      val.forEach((item) => {
        let obj = {
          id: item.id,
          num: item.nums,
        };
        this.fahuos.order_seconds.push(obj);
      });
      */
    },
    print() {
      this.$print(this.$refs.print);
      this.isdayin = true; // 2、绑定区域锚点print，进行打印
    },
    dayin() {
      this.$print(this.$refs.print);
    },
    handleSizeChange(val) {
      console.log(val);
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.getlist();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.getlist();
    },
    next() {
      console.log("ss");
      this.pagination.page = this.pagination.page + 1;
      this.getlist();
    },
  },
};
</script>

<style scoped>
#printArea {
  width: 100%;
  margin: 0 auto;
}

#printArea > div {
  margin-top: 50px;
}

#printArea > div:first-child {
  margin-top: 0px;
}

#printArea table {
  width: 100%;
  border-collapse: collapse;
}

#printArea table th {
  color: white;
  height: 50px;
  line-height: 50px;
  font-size: 35px;
}

#printArea table {
  border: 1px solid #c5c5c5;
}

#printArea table td,
table th {
  border: 1px solid #c5c5c5;
  text-align: center;
  padding: 0;
  margin: 0;
}

#printArea table tr td {
  height: 35px;
  line-height: 35px;
}

#printArea table thead th {
  background-color: #f4615c;
}

#printArea table tr th,
table tr td {
  padding: 5px 12px;
}

@page {
  size: auto;
  /* auto is the initial value */
  margin: 3mm;
  /* this affects the margin in the printer settings */
}

.procedure {
  word-wrap: break-word;
}
</style>
